package  
{
	import org.flixel.*
	
	/**
	 * A visual that can be "parented" to another sprite.
	 * @author Rob Gordon
	 */
	public class HintSprite extends FlxSprite 
	{
		private var _parentSprite:FlxSprite = null;
		private var _xOffset:int = 0;
		private var _showDuration:Number = 3.0; // show for this long
		private var _showTimer:Number = -1.0; // tracks duration of current showing
		
		public function HintSprite(graphic:Class=null)
		{
			super();
			loadGraphic(graphic);
			exists = false; // hide initially
		}
		
		public function showHint(xOffset:int, newY:int, infant:FlxSprite):void
		{
			// only show if not already being shown
			if (!exists)
			{
				_xOffset = xOffset;
				_parentSprite = infant;
				// position relative to parent
				x = infant.x + xOffset;
				y = newY;
				exists = true;
				_showTimer = 0.0;
			}
		}
		
		public function hideHint(infant:FlxSprite):void
		{
			if (infant == _parentSprite)
			{
				exists = false;
				_showTimer = -1.0;
				_parentSprite = null;
				_xOffset = 0;
			}
			//else
			//	trace("hideHint called by non-carried infant. Ignoring");
		}
		
		public override function update():void
		{
			// update x position relative to parent
			x = _parentSprite.x + _xOffset;
			_showTimer += FlxG.elapsed;
			//trace("_showTimer: " + _showTimer);
			if (_showTimer > _showDuration)
			{
				_showTimer = -1.0;
				exists = false;
			}
			
			super.update();
		}
	}
}